﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GatewayInspect.Common;
using GatewayInspect.Model;

namespace GatewayInspect.Modules
{
    public partial class SelectDriverForm : PopupForm
    {
        private DataTable _dataSourceTable;

        public string DriverID { get; set; }

        public string DriverName { get; set; }

        public SelectDriverForm()
        {
            InitializeComponent();
        }

        public SelectDriverForm(DataTable _table)
            : this()
        {
            _dataSourceTable = _table;
        }

        private void SelectDriverForm_Load(object sender, EventArgs e)
        {
            if (_dataSourceTable != null)
            {
                this.cdgvDriver.AutoGenerateColumns = false;
                this.cdgvDriver.DataSource = _dataSourceTable;
            }
        }

        private void cdgvDriver_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (cdgvDriver.SelectedCells != null && cdgvDriver.SelectedCells.Count > 0 && _dataSourceTable != null)
            {
                DataGridViewRow row = cdgvDriver.SelectedCells[0].OwningRow;
                this.DriverID = row.Cells["DRIVERID"].Value.ToString();
                this.DriverName = row.Cells["DRIVERNAME"].Value.ToString();
                this.DialogResult = DialogResult.OK;
            }
        }
    }
}
